Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertions to test if objects are extensible. #479

Merged
merged 3 commits into from
Jul 12, 2015
Merged

Assertions to test if objects are extensible. #479

merged 3 commits into from
Jul 12, 2015

Conversation

mattlucock
Copy link
Contributor

Thin assertions to test if objects are extensible, sealed, or frozen with Object.isExtensible(), Object.isSealed(), and Object.isFrozen(). Closes #478.

var nonExtensibleObject = Object.preventExtensions({});
var sealedObject = Object.seal({});
var frozenObject = Object.freeze({});

/**
 * Extensible
 */

assert.extensible({});
assert.notExtensible(nonExtensibleObject);
assert.notExtensible(sealedObject);
assert.notExtensible(frozenObject);

expect({}).to.be.extensible;
expect(nonExtensibleObject).to.not.be.extensible;
expect(sealedObject).to.not.be.extensible;
expect(frozenObject).to.not.be.extensible;

({}).should.be.extensible
nonExtensibleObject.should.not.be.extensible;
sealedObject.should.not.be.extensible;
frozenObject.should.not.be.extensible;

/**
 * Sealed
 */

assert.sealed(sealedObject);
assert.sealed(frozenObject);
assert.notSealed({});

expect(sealedObject).to.be.sealed;
expect(frozenObject).to.be.sealed;
expect({}).to.not.be.sealed;

sealedObject.should.be.sealed;
frozenObject.should.be.sealed;
({}).should.not.be.sealed;

/**
 * Frozen
 */

assert.frozen(frozenObject);
assert.notFrozen({});

expect(frozenObject).to.be.frozen;
expect({}).to.not.be.frozen;

frozenObject.should.be.frozen;
({}).should.not.be.frozen;

(I did my best to adhere to the already-established code and test style, but if there's something I didn't get quite right or something I could make better, let me know.)

@keithamus
Copy link
Member

Awesome work @matthewlucock! Great example of a thorough PR, good explanation, good code, good tests. Perfect 😍

keithamus added a commit that referenced this pull request Jul 12, 2015
Assertions to test if objects are extensible.
@keithamus keithamus merged commit 95a172b into chaijs:master Jul 12, 2015
@mattlucock mattlucock deleted the extensible-assertions branch July 13, 2015 06:29
@mattlucock mattlucock restored the extensible-assertions branch July 13, 2015 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants